//////////////////////////////////////////////////////////////////////////
//             Copyright 2014  All Rights Reserved                //
//////////////////////////////////////////////////////////////////////////
/* =======================================================================
 * 系统名   : 
 * 子系统名 : 
 * Class名  : QueueTest.java
 * 概要     : 
 * 改版履历 : 
 * 版本                     日期                    作者名             备注
 * 1.0.0    2014年12月25日        郭恩洲          初次作成
 * ======================================================================= */
package jms;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.command.ActiveMQQueue;

public class QueueTest {
    public static void main(String[] args) throws Exception {
    	ConnectionFactory factory = new ActiveMQConnectionFactory("admin","admin","tcp://10.121.49.131:61616");
    	   
        Connection connection = factory.createConnection();
        connection.start();
       

        //创建一个Queue
        Queue queue = new ActiveMQQueue("test");
        //创建一个Session
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
       

     /*   //注册消费者1
        MessageConsumer comsumer1 = session.createConsumer(queue);
        comsumer1.setMessageListener(new MessageListener(){
            public void onMessage(Message m) {
                try {
                	Thread.sleep(2000);
                    System.out.println("Consumer1 get " + ((TextMessage)m).getText());          
                } catch (JMSException e) {
                    e.printStackTrace();
                } catch (InterruptedException e) {
					e.printStackTrace();
				}
            }
        });
       

        //注册消费者2
        MessageConsumer comsumer2 = session.createConsumer(queue);
        comsumer2.setMessageListener(new MessageListener(){
            public void onMessage(Message m) {
                try {
                    System.out.println("Consumer2 get " + ((TextMessage)m).getText());
                } catch (JMSException e) {
                    e.printStackTrace();
                }
            }
           
        });*/
       

        //创建一个生产者，然后发送多个消息。
        MessageProducer producer = session.createProducer(queue);
        for(int i=0; i<10; i++){
        	producer.send(session.createObjectMessage("Message:" + i));
        }
    }
}


class MessageBean {
	private String message;
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	
	
}

